package com.mall.goods.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.goods.mapper.PmsBrandMapper;
import com.mall.model.domain.PmsBrand;
import com.mall.model.vo.CommonPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class PmsBrandService {

    @Autowired(required = false)
    private PmsBrandMapper pmsBrandMapper;

    /**
     * 根据品牌名称分页获取品牌列表
     *
     * @param keyword
     * @param pageNum
     * @param pageSize
     * @return
     */
    public CommonPage list(String keyword, Integer pageNum, Integer pageSize) {
        Page<PmsBrand> pageInfo = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<PmsBrand> queryWrapper = new LambdaQueryWrapper<>();
        //查询条件
        queryWrapper.like(keyword != null, PmsBrand::getName, keyword);
        Integer count = pmsBrandMapper.selectCount(queryWrapper);
        pmsBrandMapper.selectPage(pageInfo, queryWrapper);
        return new CommonPage(pageNum, pageSize, count, pageInfo.getRecords());
    }

    public PmsBrand selectById(Integer id) {
        return pmsBrandMapper.selectById(id);
    }

    public void updateFactoryStatus(List<Integer> ids, Integer factoryStatus) {
        LambdaQueryWrapper<PmsBrand> qw = new LambdaQueryWrapper<>();
        qw.in(PmsBrand::getId, ids);
        PmsBrand brand = new PmsBrand();
        brand.setFactoryStatus(factoryStatus);
        pmsBrandMapper.update(brand,qw);
    }

    public void updateShowStatus(ArrayList<Integer> ids, Integer showStatus) {
        LambdaQueryWrapper<PmsBrand> qw = new LambdaQueryWrapper<>();
        qw.in(PmsBrand::getId, ids);
        PmsBrand brand = new PmsBrand();
        brand.setShowStatus(showStatus);
        pmsBrandMapper.update(brand,qw);
    }

    public void updateById(Integer id, PmsBrand pmsBrandParam) {
        pmsBrandMapper.updateById(pmsBrandParam);
    }

    public List<PmsBrand> selectAll() {
        return pmsBrandMapper.selectList(null);
    }

    public void delete(Integer id) {
        pmsBrandMapper.deleteById(id);
    }

    public void deleteBatch(List<Integer> ids) {
        pmsBrandMapper.deleteBatchIds(ids);
    }

    public void create(PmsBrand pmsBrandParam) {
        pmsBrandMapper.insert(pmsBrandParam);
    }
}
